//
//  TransferGoodsHeaderCell.swift
//  甜言蜜语
//
//  Created by yingli_yanfa_liuxingyu on 16/8/31.
//  Copyright © 2016年 wl. All rights reserved.
//

import UIKit
protocol TransferGoodsHeaderCellDelegate {
    func callAction(text: String)
    func reportAction(text: String)
    func ivSelected()
}
class TransferGoodsHeaderCell: UITableViewCell {
    var model:TransferDetailModel?{
        didSet{
            self.setCellContentWithCellInfo((self.model?.body)!)
            self.setupView()
        }
    }
    @IBOutlet weak var price: UILabel!
    @IBOutlet weak var area: UILabel!
    @IBOutlet weak var address: UILabel!
    @IBOutlet weak var tel: UILabel!
    @IBOutlet weak var body: UILabel!
    @IBOutlet weak var cyclePicture: CyclePictureView!
    @IBOutlet weak var treasureType: UILabel!
    @IBOutlet weak var titel: UILabel!
    @IBOutlet weak var buyPrice: UILabel!
    @IBOutlet weak var newOld: UILabel!
    @IBOutlet weak var browerNum: UILabel!
    @IBOutlet weak var time: UILabel!
    @IBOutlet weak var dvertisersIv: UIImageView!
    @IBOutlet weak var dvertisersName: UILabel!
    
    @IBOutlet weak var detailView: UIView!
    @IBOutlet weak var detailViewCons: NSLayoutConstraint!
    @IBOutlet weak var reportBtn: UIButton!
    var delegate: TransferGoodsHeaderCellDelegate?
    override func awakeFromNib() {
        super.awakeFromNib()
        self.dvertisersIv.layer.masksToBounds = true
        self.dvertisersIv.layer.cornerRadius = 16.5
        // Initialization code
    }
    func setCellContentWithCellInfo(text: String) -> Void {
        let font = UIFont(name: "Helvetica", size: 16)
        let height = publicMethod.getLabHeigh(text, font: font!, width: SCREEN_WIDTH - 16) + 29 + 15
       
        self.detailViewCons.constant = height
        self.detailView.layoutIfNeeded()
        
    }
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    func setupView() -> Void {
        price.text = String(format: "%@元",(model?.price)!) 
        titel.text = model?.name
        time.text = publicMethod.computationTimeDifference((self.model?.ptime)!)
        buyPrice.text = model?.buyprice
        treasureType.text = model?.treasureType
        area.text = model?.area
        address.text = model?.address
        tel.text = model?.tel
        body.text = model?.body
        newOld.text = model?.newold
        browerNum.text = String(format: "已有%@人浏览",(model?.browerNum)!)
        dvertisersIv.sd_setImageWithURL(NSURL(string: (model?.usertimg)!), placeholderImage: UIImage(named: "placeholder"))
        
        dvertisersName.text = model?.username
        var images: [String] = []
        for item in model!.transferPics {
            images.append(item.imgurl)
        }
        
        cyclePicture.imageURLArray = images 
        
        
    }
    
    @IBAction func callBtn(sender: UIButton){
        delegate?.callAction((model?.tel)!)
    }
    @IBAction func reportBtnSelected(sender: UIButton){
        delegate?.reportAction(String(self.model?.id))
    }
    @IBAction func ivTap(sender: UIButton) {
        delegate?.ivSelected()
    }
    
}
